Skip to content

Speed up the timeline's frames around its kept rows, and say why they aren't #[Memo] - #187

Merged
simonhamp merged 18 commits into
mainfrom
perf/memo-timeline-rows
Nov 25, 2026
Merged

simonhamp merged 18 commits into
mainfrom
perf/memo-timeline-rows

Conversation

@simonhamp

@simonhamp simonhamp commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

This is on main now. It was based on integration/timeline-memo-base, and all ten PRs in that branch have merged. Main's commit page builds its rows in CommitDetail::pageRows(), so the commit page's row caching was redone for that.

Why the rows aren't #[Memo] components

The question was whether the Log and profile rows use #[Memo] from mobile-air 4.8. They don't, and they shouldn't. Since #40 they go through App\Devnull\RowCache, which already does what Memo does and a bit more: it keeps each row's elements and the node it sent, against a hash of what the row shows, so an unchanged row costs one hash a frame.

I turned the feed's commit and reply rows into a #[Memo] child component on mobile-air 4.8.0 and timed both on the same data. Memo was slower on every step:

PHP per step, Mac RowCache #[Memo]
Log, star a commit 6.8 ms 10.7 ms
Log, open and close a sheet 11.5 ms 20.0 ms
Log, nothing changes, 60 commits 6.4 ms 18.8 ms
Log, pull to refresh, 60 commits 7.7 ms 23.6 ms
Profile, star a commit 7.2 ms 11.1 ms

Two reasons. The Log, profiles, Search and Starred send every frame in full ($forceFullFrames), and Memo's shortcut is a reuse marker that only works with subtree reuse on, so it walks and serialises every kept row again each frame. CachedRow skips that walk. And Memo compares a child's props every frame by serialising any object among them, which here is the Commit, where RowCache hashes each readonly commit once. So the rows stay where they are and this PR goes after the rest of each frame. The prototype isn't in this PR. Those timings were taken before #189 was merged into this branch and turned full frames off.

What changed

  • A row asked the account for your pastéis again whenever the screen passed null, which it does with pastéis mode off. That's a SQLite query on a phone, so a frame on the Log ran one per row. Null now counts as an answer, for $viewer too.
  • The skeleton rows, the loading row at the end of a list, the root commit row, day markers, the last-visit marker and a profile's pinned commit were built afresh every frame. They now go through the list's RowCache with its commits, on the Log, profiles, organizations, Starred and Search. On the Log that was five rows on every frame.
  • The log beside yours read its kept answer and parsed its first commits again every frame. It's now kept with a hash of what it came from and only made again when that changes.
  • A row is kept against its own drafts and its own Show more, not the whole list, so the first letter of a quote or reply no longer builds every row on the screen.
  • A commit page's commits now go through the page's RowCache like its replies. That's every commit row pageRows() gives (the commits above, the commit, its series and its author's thread) and the related commits. Typing a reply used to build all of them on every frame. The focused commit is also kept against whether its replies are open, its reply count and your timezone.
  • Found by the new kept-row checks: a poll's Vote button wears your lane colour, which RowInputs didn't cover, so after changing your colour the Log kept the old one on that button.
  • Send only what changed on the timeline screens #189 was merged into this branch. It turns $forceFullFrames off on the timeline screens, and CachedRow sends a kept row as reuse markers where the phone already holds it. Its own PR has the details and numbers.

Every frame should be the same as before. Before the move, the bench below recorded the tree each step ends on, and all 336 of them matched the old base branch's, node for node: about 204 KB a frame on a Log of 20 commits and 530 KB with 60, measured as the tree's JSON, before #189. On main, the kept-row tests check every kept row against one built afresh, and PartialFramesTest checks the phone's tree against a full frame after each step.

Numbers

All of these were measured before the move, against integration/timeline-memo-base and without #189. The bench isn't in this repo, so they haven't been re-run on main.

Mac, PHP only (render plus toArray, median of 11 runs, same fixtures, cache in SQLite and kept answers in files as on a phone):

Step Before After
Log, first render, 20 commits 43.4 ms 40.7 ms
Log, a frame where nothing changes 7.1 ms 3.2 ms
Log, star a commit 8.8 ms 5.1 ms
Log, open a thread 16.0 ms 11.9 ms
Log, close it 8.7 ms 4.9 ms
Log, open and close the quote sheet 15.8 ms 8.4 ms
Log, next page goes in while scrolling 42.4 ms 34.5 ms
Log, next page at the end 40.9 ms 34.5 ms
Log, star with 60 commits 12.1 ms 6.1 ms
Log, nothing changes with 60 commits 10.2 ms 4.3 ms
Log, pull to refresh 11.1 ms 5.2 ms
Profile Commits, first render 37.8 ms 37.5 ms
Profile Commits, star a commit 9.5 ms 7.1 ms
Profile Commits, open a thread 17.3 ms 14.5 ms
Profile Commits, nothing changes 8.1 ms 5.3 ms
Profile Replies, switch to the tab 36.9 ms 36.8 ms
Profile Replies, star a reply 10.2 ms 8.0 ms
Organization, star a commit 7.9 ms 5.2 ms
Organization, nothing changes 7.0 ms 3.8 ms
Commit page, first letter of a reply 12.3 ms 5.2 ms
Commit page, next letter 6.4 ms 3.6 ms

On an iOS 27 simulator and an Android 15 emulator, a debug build of each side ran a scripted session against a fake API serving the same fixtures, one step every 1.5 s, timed from mobile-air's own PERF lines in edge-nav.log. This is the frame each step caused, render plus toArray, median of five runs:

Step iOS before iOS after Android before Android after
Log, every frame where nothing changed 12.3 ms 5.1 ms 8.9 ms 5.6 ms
Log, star a commit 15.3 ms 7.6 ms 8.2 ms 6.3 ms
Log, open a thread 30.9 ms 19.0 ms 17.7 ms 15.0 ms
Log, close it 29.5 ms 20.2 ms 11.9 ms 7.9 ms
Log, open the quote sheet 23.6 ms 17.6 ms 15.5 ms 14.4 ms
Log, next page goes in while scrolling 43.9 ms 38.3 ms 32.3 ms 31.0 ms
Log, star with 60 commits 15.7 ms 8.0 ms 10.8 ms 8.5 ms
Log, pull to refresh 15.0 ms 6.4 ms 11.3 ms 7.7 ms
Profile, every frame where nothing changed 11.9 ms 8.7 ms 7.9 ms 6.0 ms
Profile, star a commit 13.3 ms 7.9 ms 9.8 ms 7.6 ms
Profile, open a thread 21.8 ms 19.4 ms 14.1 ms 10.1 ms
Profile, switch to Replies 38.0 ms 28.9 ms 8.7 ms 9.0 ms
Profile, star on Replies 13.7 ms 11.1 ms 11.5 ms 7.1 ms

First renders barely move on either: building a row costs about the same as before (about 1 ms each on a Mac), and that's most of a first render.

The bench, the timing harness and the fake API aren't in this PR. They're attached to the board entry for this task, with how to run them.

What to watch for

RowInputs is the contract: anything a row partial reads from its screen has to be in it, or a kept row shows what it showed before. The tests in LogRowCacheTest and RowCacheScreensTest now change a star, the time, your timezone, your colour, your organizations, a draft, Show more and a thread's state, and check kept rows against rows built afresh. A partial that starts reading something new needs adding there too.

On the commit page the rows come from CommitDetail::pageRows(). A commit row's data says where it sits in the tree: its rail, its place in its author's thread, and an ancestor's reply count. RowInputs says whether an ancestor's replies are open. The commit the page is about also reads its replies' state and your timezone from the page, so those are in its inputs as well (commit-detail.blade.php). The tests fail if either is taken out. They now also open and fold the replies of a commit above, move the page up, down and onto a reply, and walk a self thread. PartialFramesTest's commit page case moves the page around its tree too.

Full suite on main: 2304 passed, 12 skipped. The skips are the nine edge blur tests, two that need NativePHP/mobile-air#736, and one that only runs without core's menu row subtitles.

Not done here

  • A Log frame still runs about 14 cache queries and a profile frame about 21, mostly Account::user() asked again from several places. Remembering it for a frame would cut most of them, but background tasks read the same keys from another runtime, so it needs care.
  • A commit row is about 48 nodes and costs about 1 ms to build on a Mac, commit-actions and commit-row-content most of it. That's what first renders, next pages and opening threads pay for. Fewer nodes per row is the lever there.
  • For #[Memo] to help a list in mobile-air, a memoised child would need to keep its serialised node on full-frame screens, as CachedRow does, and compare object props without serialising them every frame.

Screenshots

Nothing a user sees changed. Before the move every frame matched the base branch's, and on main the kept rows match rows built afresh. Checked by hand before the move on an iOS simulator and an Android emulator in light and dark: starring, opening and closing threads, the quote sheet, next pages, pull to refresh, a profile's tabs, and a commit page's replies and reply bar all update as before.

  • No visible change

🤖 Generated with Claude Code

@simonhamp
simonhamp marked this pull request as ready for review November 25, 2026 11:32
simonhamp and others added 18 commits November 25, 2026 12:08
With pastéis mode off, the screen passes $pasteis as null, and both
RowInputs::for() and commit-actions treated null as "not given" and
asked the account again. That's a query on the phone, where the cache
is the app's SQLite database, so every row on the Log cost one on every
frame, kept or not: 24 queries a frame on a log of 20.

Null is now an answer. The account is only asked when the screen passed
nothing at all. The same goes for $viewer, which is null when you're
signed out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every frame built the rows around the commits afresh: the skeleton rows
of a log or tab with nothing loaded, the loading row at the end of a
list, the root commit row, the day markers and the last-visit marker,
and a profile's pinned commit. On the Log that was five skeleton and
loading rows on every frame, about a third of a frame where nothing
changed.

They now go through the list's RowCache like its commits, on the Log,
profiles, organizations, Starred and Search. Each is kept against what
it draws, so a loading row that stops pulsing when you swipe away is
built again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every frame read the answer kept for the log beside yours and made its
first commits afresh, with their bodies parsed again. New commits then
missed the timeline laid out for them last frame and the rows kept for
them, so each was hashed again too.

The preview is now kept with a hash of what it was made from, and only
made again when that changes, as it does when a star or a delete
reaches the kept answer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A poll you can vote on draws its Vote button in your lane colour, which
the row reads from the screen. RowInputs didn't have it, so after you
changed your colour the Log kept the old one on that button until the
row changed for some other reason.

The kept-row test now also changes your colour and joins you to an
organization whose commit is showing, and checks the kept rows against
rows built afresh, as it did for stars, times and threads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RowInputs kept every row against the whole list of stashed drafts and
unfolded commits, though a row only shows its own: a dot on its Quote or
Reply button, and its body whole once you tapped Show more. Starting a
draft anywhere, as the first letter of a quote or a reply does, built
every row on the screen again.

Each row is now kept against its own drafts and its own unfolding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The commit a page is about, what it replies to, the rest of its series
and the related commits were built again on every frame. Typing a reply
draws a frame a few times a second, so each letter built every commit
above the reply bar.

They now go through the page's RowCache with its replies. The commit
the page is about is also kept against what it shows of its thread
(whether its replies are open, and how many) and your timezone, which
its time's label is in. The test changes each of those, and the time,
and checks the kept rows against rows built afresh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since #187 was started, main's commit page grew a few ways for a
commit row to change without its commit changing: the replies of a
commit above it open and fold in place, tapping a commit in the tree
moves the page to it, and an author's replies to themselves read as a
thread under the commit.

Each of these now gets the same check as the rest: the kept rows must
match rows built afresh. That covers an ancestor's replies opening,
fading out and folded, the page moving up, back down and down to a
reply, and a self thread with its replies opened and closed, the time
passing and the page moving to a later part. Typing a reply still only
builds the commit it replies to, once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CachedRow sent its kept node in full every frame, so with EDGE's subtree
reuse on, a list whose rows are kept still went out whole whenever any
row changed. It now builds a row against no hashes, so the kept node is
always whole, and sends it the way EDGE's own walk sends a node: a reuse
marker for any part the phone holds by id and hash, the rest in full.

Nothing changes while a screen sets $forceFullFrames, because the hashes
start empty every frame there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Log sent every frame in full because EDGE's subtree reuse could refer
to rows the phone never got, which drew the list blank after a pull to
refresh. That is fixed in nativephp/mobile by NativePHP/mobile-air#699:
the reader parses every frame instead of dropping some, a row's id is
part of its hash, and a reader that still can't build a frame asks PHP
for a full one. With that, a star on a 60 commit Log sends about 9 KB
instead of 530 KB.

This needs that fix. On mobile-air 4.8.0 without it, the Log goes blank
again, so the new test skips itself there.

The test replays every frame the way the phone's reader does and checks
the result against a full frame after each step: a star, a thread, the
next page, new commits on top, back to the top, a delete from the middle,
the pill, the image viewer and a swipe to another log and back.

The other screens that set the flag no longer point at the Log's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A profile went in full so that a tab tapped again, which puts the same
rows in a list with a new key, still reached the phone. With a row's id
in its hash (NativePHP/mobile-air#699), the new list no longer matches
the old one, so it is sent as it should be.

The test covers a star, a thread, the tab tapped again, and a swipe to
Replies and back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An organization's page is built like a profile's and went in full for the
same reason: a tab tapped again puts the same rows in a list with a new
key. That reaches the phone now (NativePHP/mobile-air#699).

The test covers a star, a thread, the tab tapped again, and a swipe to
Mentions and back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A tap into the reply field mounts the thread's scroll view again under a
new key, and subtree reuse then pointed at rows the phone had dropped, so
the thread went blank as you started typing. The new key now changes the
scroll view's hash (NativePHP/mobile-air#699), so it goes out whole, and
each letter typed after that sends only the reply bar.

The test opens the earlier commits and the replies, taps into the field
twice, and types.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Starred went in full because rows leave its list from the middle. The
rows are keyed, so the frame after an unstar refers to the rows that
stay by id, and with the reader parsing every frame
(NativePHP/mobile-air#699) the phone has all of them.

The test unstars rows from the middle and the top, with a thread open
under one of them, and pulls to refresh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Notifications went in full for the same reason as the Log: subtree reuse
could refer to rows the phone never got and draw the list blank. Those
were frames the phone's reader dropped, which it no longer does
(NativePHP/mobile-air#699).

The test opens a group, brings two new notifications in on top, loads
the next page, closes the group and turns every kind back on, which puts
the list under a new key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Remotes went in full because a conversation with a new message moves to
the top. Its rows are keyed, so the move refers to them by id, and the
tab tapped again now reaches the phone as a new list
(NativePHP/mobile-air#699).

The test moves two conversations to the top from the middle and lower
down, taps the tab again, swipes to Fetched and back, and checks the
order the phone ends up with.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Search went in full because a new term replaces every row. New rows are
new ids, which go out in full anyway, and rows a term shares with the
last one are referred to by id, which the phone now always holds
(NativePHP/mobile-air#699).

The test picks a term, types more of it, switches to a term with the
same commits in another order, goes back, and clears the field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A thread went in full because messages come in at the bottom and their
reactions change in place. Both are ordinary changes to keyed rows, and
the frames that carried them are no longer dropped by the phone's reader
(NativePHP/mobile-air#699).

The test polls in a message and a reaction, types, hearts a message,
replies and sends, loads older messages above, and polls again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The commit page's commits are now kept between frames and sent as
reuse markers where the phone holds them. On main the page also moves
to another commit in its tree without a new scroll view, and the
commits above open their replies in place.

The partial frames case for the commit page now moves up to the
parent, opens and folds the root's replies, moves back down and then
down to a reply, and checks the phone's tree against a full frame after
each step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@simonhamp
simonhamp force-pushed the perf/memo-timeline-rows branch from 3acacc1 to a4f7fcf Compare November 25, 2026 12:20
@simonhamp
simonhamp changed the base branch from integration/timeline-memo-base to main November 25, 2026 12:20
@simonhamp
simonhamp merged commit 332aee6 into main Nov 25, 2026
6 checks passed
simonhamp added a commit that referenced this pull request Nov 25, 2026
Main's commit page kept replyTapped() and the scroll view's $scrollKey,
and gained a lot around them: moving the page around its tree, animated
scrolls, and #187's partial frames.

This keeps all of that and still drops the jump. $scrollKey and
replyTapped() go, the scroll view's key is plain "thread", and the reply
field has no press handler. PartialFramesTest loses its two steps that
tapped the reply field, since the tap no longer does anything.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@simonhamp
simonhamp deleted the perf/memo-timeline-rows branch November 25, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant